package pATT.decisionMaking;

import java.util.Observable;
import java.util.Vector;

import pATT.profile.ComponentLeaf;
import pATT.profile.ComponentTree;
import pATT.profile.Profile;

public class DMECTree extends DMAlgorithm {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** Valor umbral*/
	private double t2;
	/** Valor umbral para realizar una sugerencia */
	//  private double t3;
	/** Valor umbral*/
	private double t1;
	
	
	
	public DMECTree(Profile p) {
		
		t1=0.1;
		t2=0.7;
		//t3=0.3;
		p.addObserver(this);
		
	}

	public DMECTree() {
		
		t1=0.1;
		t2=0.7;
		//t3=0.3;
		//p.addObserver(this);
		
	}

	  public void setT1(double t){ t1=t; }
	  public double getT1(){ return t1; }
	  public void setT2(double t){ t2=t; }
	  public double getT2(){ return t2; }

	
	/**
	 * 0-p1= No confidence Evaluation (percentage)
	 * p1-p2= Medium confidence Evaluation  (percentage)
	 * p2-1= High confidence Evaluation (percentage)
	 * */
	@Override
	public String makeDecision(Vector sit, Profile p) {
		p.addObserver(this);
		String asistencia = "";
		
		if(!p.getComponents().isEmpty()){
			ComponentTree root = (ComponentTree)p.getComponents().get(0);
			ComponentLeaf leaf = (ComponentLeaf)root.appliesTo(sit);
			if(leaf == null){
				//veer que hacer
			}else{
				double confianza = 0;
				if(leaf.getValueNotExist()+leaf.getValueExist() != 0)
						confianza = leaf.getValueExist()/(leaf.getValueExist()+leaf.getValueNotExist());
				String percentage = "("+confianza*100+"%)";
				
				if ((confianza >=0) && (confianza < t1))
					asistencia="No confidence Evaluation ";
				else if ((confianza >= t1) && (confianza < t2))
					asistencia="Medium confidence Evaluation ";
				else if((confianza >= t2)&& (confianza <= 1))
					asistencia="High confidence Evaluation ";
				
				asistencia = leaf.getValueAtt()+" - "+asistencia+percentage;
				
			}
		}
		return asistencia;
	}
	
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean hasInstances() {
		return true;
	}
	
}
